home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Utilities / ResEdit / Examples / PExamples / Source / ResEd.p < prev    next >
Text File  |  2022-08-05  |  12KB  |  324 lines

  1. {
  2.  COPYRIGHT (C) 1984-1989 Apple Computer,Inc.
  3.  All rights reserved
  4.  
  5.     Resource editor interface unit for instances of editors and pickers. This should be
  6.     USE'd by any pascal implementation of a resource editor or picker.  The
  7.     companion file ResDisp.a.o should be linked with the pascal to build
  8.     the file for inclusion in ResEdit.
  9.     
  10.     Pickers are given a resource type and should display all of that type in 
  11.     the current resfile in a suitable format.     If the picker is given an open call 
  12.     AND there's a compatible editor, it should give birth to the Editor.  The editor
  13.     is given a handle to the resource object and it should open up an edit
  14.     window for the user.
  15.  
  16.     Note that anybody can open pickers and editors so, for instance, a dialog item list
  17.     editor might open an icon Picker for the user to choose an appropriate icon.
  18.     The user could also, while in the icon picker, open the icon editor to create
  19.     a new icon if desired. }
  20.  
  21.  
  22. UNIT ResEd;
  23.  
  24.  
  25. INTERFACE
  26.  
  27. Uses    Memtypes, QuickDraw, OSIntf, ToolIntf;
  28.  
  29.  
  30. CONST
  31.  
  32.     { Standard menus exported by ResEdit }
  33.  
  34.     fileMenu    = 2;
  35.  
  36.     newItem         = 1;
  37.     openItem        = 2;
  38.     openAsItem        = 3;
  39.     opnOther        = 3;
  40.     openGeneralItem = 4;
  41.     opnGnrl         = 4;
  42.     closeItem       = 6;
  43.     saveItem         = 7;
  44.     revertItem      = 8;
  45.     getInfoItem     = 9;
  46.     preferencesItem = 10;
  47.     transferItem     = 12;
  48.     quitItem        = 13;
  49.     
  50.     { Masks for AbleMenu - normally not used directly. }
  51.     newMask         = $2;
  52.     openMask         = $4;
  53.     openAsMask         = $8;
  54.     openGnrlMask    = $10;
  55.     closeMask        = $40;
  56.     saveMask        = $80;
  57.     revertMask        = $100;
  58.     getInfoMask        = $200;
  59.     preferencesMask = $400;
  60.     transferMask    = $1000;
  61.     quitMask        = $2000;
  62.     disabledMask    = $FFFFC001;
  63.     
  64.     { Mask combinations to be used in calls to AbleMenu. }
  65.     fileQuit      = disabledMask + preferencesMask + transferMask + quitMask;
  66.     fileClose      = fileQuit + closeMask + saveMask;
  67.     fileAll          = fileClose + newMask + openMask + openAsMask + openGnrlMask + revertMask + getInfoMask;
  68.     fileNoRevert  = fileAll - revertMask;
  69.     fileNoInfo      = fileAll - getInfoMask;
  70.     fileNoNew      = fileAll - newMask; 
  71.     fileNoOpen       = fileClose + newMask + revertMask + getInfoMask;
  72.     fileNoNewOrOpen = fileNoOpen - newMask;
  73.     fileTop          = fileClose + revertMask + getInfoMask;
  74.     fileOpQuOnly  = fileQuit + openMask + openAsMask + openGnrlMask;
  75.     fileROMStuff  = fileQuit  + openMask + openAsMask + openGnrlMask + closeMask + getInfoMask;
  76.     fileDiskStuff = fileQuit + newMask + openMask + closeMask + getInfoMask;
  77.  
  78.     editMenu    = 3;
  79.  
  80.     undoItem    = 1;
  81.     cutItem     = 3;
  82.     copyItem    = 4;
  83.     pasteItem   = 5;
  84.     clearItem   = 6;
  85.     dupItem     = 8;
  86.     
  87.     { Masks for AbleMenu - normally not used directly. }
  88.     undoMask        = $2;
  89.     cutMask            = $8;
  90.     editCopyMask    = $10;
  91.     pasteMask        = $20;
  92.     clearMask        = $40;
  93.     duplicateMask    = $100;
  94.     editDisabledMask= $FFFFFE01;
  95.  
  96.     { Mask combinations to be used in calls to AbleMenu. }
  97.     editNone    = editDisabledMask;
  98.     editClear    = editNone + clearMask;
  99.     editCopy    = editNone + editCopyMask;
  100.     editPaste    = editNone + pasteMask;
  101.     editUndoPasteOnly = editPaste + undoMask;
  102.     editDup        = editClear + duplicateMask;
  103.     editNoDup    = editNone + cutMask + editCopyMask + pasteMask + clearMask; { No dup or undo }
  104.     editNoUndo    = editNoDup + duplicateMask;
  105.     editUndNoDup= editNoDup + undoMask;
  106.     editAll        = editNoUndo + undoMask;
  107.     editAcc     = editUndNoDup;
  108.  
  109.     editorNameChr     = CHR(0);        { First char of the name for editors }
  110.     
  111.     { Standard strings available by calling GetStr. }
  112.     editStrings        = 130;            { Resource ID of STR# resource containing the strings. }
  113.     undoChangeStr    = 1;
  114.     redoChangeStr    = 2;
  115.     undoCutStr        = 3;
  116.     redoCutStr        = 4;
  117.     undoCopyStr        = 5;
  118.     redoCopyStr        = 6;
  119.     undoClearStr    = 7;
  120.     redoClearStr    = 8;
  121.     undoTypingStr    = 9;
  122.     redoTypingStr    = 10;
  123.     undoPasteStr    = 11;
  124.     redoPasteStr    = 12;
  125.     undoStr            = 13;
  126.     
  127.     miscStrings            = 129;        { Resource ID of STR# resource containing the strings. }
  128.     fromStr                = 1;        { String for window titles. }
  129.     fullWindowStr         = 38;        { String for the resizeWind menu item }
  130.     ownerWindowWindowStr= 39;
  131.     newItemStr             = 40;        { Enter new item number }
  132.     selectItemStr         = 41;        { Open which item? }
  133.     clipBoardErrorStr    = 42;        { Error accessing the Clipboard. } 
  134.     sndErrorStr            = 43;        { Error playing a sound. }
  135.     openAsDotStr        = 44;        { Open As ... }
  136.     openAsDITMStr        = 45;        { Open As Dialog Item }
  137.  
  138.     arrowCursor     = -1;    { Used in the call to SetTheCursor to set the arrow cursor. }
  139.     
  140.     minPickStdWidth = 150;
  141.     minPickStdRows     = 4;
  142.     
  143.     okChoice = 1;
  144.     
  145.     revertResourceAlert = 1387;        { Used by all editors to when revert is selected. }
  146. TYPE
  147.     STR64 = STRING[64];
  148.  
  149.     AlertType = (displayTheAlert, displayStopAlert, displayNoteAlert, displayCautionAlert);
  150.  
  151.     { Map entry definition for new resource manager calls. }
  152.     ResMapEntry = RECORD
  153.         RID: INTEGER;
  154.         RNameOff: INTEGER;
  155.         RLocn: LongInt;
  156.         RHndl: Handle;
  157.     END;{ ResMapEntry }
  158.  
  159.     { This structure is used by the GetQuickDrawVars procedure. }
  160.     pQuickDrawVars = ^QuickDrawVars;
  161.     QuickDrawVArs = RECORD
  162.         randSeed:     LONGINT;
  163.         screenBits: BitMap;
  164.         arrow:         Cursor;
  165.         dkGray:     Pattern;
  166.         ltGray:     Pattern;
  167.         gray:         Pattern;
  168.         black:         Pattern;
  169.         white:         Pattern;
  170.         thePort:     GrafPtr;
  171.     END; { QuickDrawVars }
  172.         
  173.  
  174.     {    Each driver has its own object handle. This has to start with a handle
  175.         to its parent's object followed by the name distinguishing the father
  176.         This name will be part of the son's window title. The next field should
  177.         be the window of the obj (may be used by son to get back to the father
  178.         (through the refcon in the windowRec). The next field is the rebuild flag
  179.         used to indicate that a windows data (e.g. a pickers list) needs to be
  180.         recalculated at the next opportunity.  The rest of the handle can be of
  181.         any format.  The name for pickers should be the name of the file or disk.
  182.         For editors, the name should be the complete name (not the windows title)
  183.         preceded by an editorNameChr character (see const above).  An example of a
  184.         complete name would be "ALRT ID = -1234 from AFile".  This name is used to
  185.         uniquely identify a window.  
  186.         
  187.         See the manual for detailed documentation of this interface file. }
  188.  
  189.     ParentPtr = ^ParentRec;
  190.     ParentHandle = ^ParentPtr;
  191.  
  192.     ParentRec = RECORD
  193.       father: ParentHandle;
  194.       name: str64;
  195.       wind: WindowPeek;
  196.       rebuild: BOOLEAN;            { Flag set by son to indicate that world }
  197.                                 { has changed so father should rebuild list }
  198.     END;
  199.  
  200.     { Standard picker record }
  201.  
  202.     PickPtr = ^PickRec;                { Any type is OK here }
  203.     PickHandle = ^PickPtr;
  204.  
  205.     PickRec = RECORD
  206.         father: ParentHandle;        { Back ptr to dad }
  207.         fName: STR64;
  208.         wind: WindowPtr;            { Directory window }
  209.         rebuild: BOOLEAN;
  210.         pickID: INTEGER;            { ID of this picker }
  211.         rType: ResType;                { Type for picker }
  212.         rNum: INTEGER;                { Resfile number }
  213.         rSize: LONGINT;                { Size of a null resource }
  214.         nInsts: INTEGER;            { Number of instances }
  215.         instances: ListHandle;        { List of instances }
  216.         drawProc: Ptr;                { List draw proc }
  217.         scroll: ControlHandle;        { Scroll bar }
  218.     END;
  219.  
  220.             
  221.  
  222. { These routines are used to start pickers and editors. }
  223.  
  224.     PROCEDURE GiveEBirth (resHandle: Handle; pick: PickHandle);
  225.     PROCEDURE GiveSubEBirth (resHandle: Handle; pick: PickHandle);
  226.     PROCEDURE GiveThisEBirth (resHandle: Handle; pick: PickHandle; openThisType:ResType);
  227.  
  228. { These routines are used to feed events and menu calls to the appropriate picker or editor. }
  229.     PROCEDURE CallInfoUpdate (oldID, newID: INTEGER; refcon: LONGINT; id: INTEGER );
  230.     PROCEDURE PassMenu (menu, item: INTEGER; father: ParentHandle);
  231.  
  232.  
  233. { Window Utilities }
  234.  
  235.     FUNCTION  AlreadyOpen (VAR windowTitle, windowName: STR255; father: ParentHandle): BOOLEAN;
  236.     FUNCTION  CWindSetup (width, height: INTEGER; t, s: STR255): WindowPtr;
  237.     FUNCTION  EditorWindSetup (color: BOOLEAN; width, height: INTEGER; 
  238.                                VAR windowTitle, windowName: STR255; addFrom: BOOLEAN; 
  239.                                father: ParentHandle): WindowPtr;
  240.     PROCEDURE GetWindowTitle (VAR windowTitle, windowName: STR255; addFrom: BOOLEAN; father: ParentHandle);
  241.     PROCEDURE SetETitle (h: Handle; VAR str: STR255);
  242.     FUNCTION  WindAlloc: WindowPtr;
  243.     PROCEDURE WindReturn (w: WindowPtr);
  244.     FUNCTION  WindList (w: WindowPtr; nAcross: INTEGER; cSize: Point; drawProc:INTEGER): ListHandle;
  245.     PROCEDURE WindOrigin (w: WindowPtr);
  246.     FUNCTION  WindSetup (width, height: INTEGER; t, s: STR255): WindowPtr;
  247.  
  248. { Extended Resource Manager }
  249.  
  250.     FUNCTION  CurrentRes: INTEGER;
  251.     FUNCTION  Get1Index (t: ResType; index: INTEGER): Handle;
  252.     FUNCTION  Get1Res (t: ResType; id: INTEGER): Handle;
  253.     FUNCTION  NeedToRevert (myWindow: WindowPtr; theRes: Handle): BOOLEAN;
  254.     PROCEDURE RemoveResource (theRes: Handle);
  255.     FUNCTION  RevertThisResource (theObj: ParentHandle; res: Handle): BOOLEAN;
  256.     FUNCTION  SysResFile: INTEGER;
  257.  
  258. { Miscellaneous utilities }
  259.     
  260.     PROCEDURE Abort;
  261.     PROCEDURE AbleMenu (menu: INTEGER; enable: LONGINT);
  262.     FUNCTION  AddNewRes (hNew: Handle; t: ResType; idNew: INTEGER; s: str255): BOOLEAN;
  263.     PROCEDURE BubbleUp (h: Handle);
  264.     FUNCTION  BuildType (t: ResType; l: ListHandle): INTEGER;
  265.     FUNCTION  CheckError (err, msgID: INTEGER): BOOLEAN;
  266.     FUNCTION  CloseNoSave: BOOLEAN; 
  267.     PROCEDURE ConcatStr (VAR str1: STR255; str2: STR255);
  268.     FUNCTION  DefaultListCellSize:INTEGER;         
  269.     FUNCTION  DisplayAlert (which: AlertType; id: INTEGER): INTEGER;
  270.     PROCEDURE FixHand (s: LONGINT; h: Handle);
  271.     PROCEDURE FlashDialogItem (dp: DialogPtr; item: integer);
  272.     PROCEDURE FrameDialogItem (dp: DialogPtr; item: integer);
  273.     FUNCTION  GetQuickDrawVars: pQuickDrawVars;
  274.     PROCEDURE GetStr (num, list: INTEGER; VAR str: STR255);
  275.     PROCEDURE GrowMyWindow (minWidth, minHeight: INTEGER; windPtr: WindowPtr; lh: ListHandle);
  276.     FUNCTION  HandleCheck (h: Handle; msgID: INTEGER): BOOLEAN;
  277.     PROCEDURE MetaKeys (VAR cmd, shift, opt: BOOLEAN);
  278.     FUNCTION  NewRes (s: LONGINT; t: ResType; l: ListHandle; VAR n: INTEGER): Handle;
  279.     PROCEDURE PickEvent (VAR evt: EventRecord; pick: PickHandle);
  280.     PROCEDURE PickInfoUp (oldID, newID: INTEGER; pick: PickHandle);
  281.     PROCEDURE PickMenu (menu, item: INTEGER; pick: PickHandle);
  282.     FUNCTION  PickStdRows: INTEGER;
  283.     FUNCTION  PickStdWidth: INTEGER;
  284.     FUNCTION  ResEdID: INTEGER;
  285.     PROCEDURE SendRebuildToPickerAndFile (theType: ResType; parent: ParentHandle) ;
  286.     PROCEDURE SetResChanged (h: Handle);
  287.     PROCEDURE SetTheCursor (whichCursor: INTEGER);
  288.     PROCEDURE ShowInfo (h:Handle; father: ParentHandle);
  289.     PROCEDURE TypeToString (t: ResType; VAR s: Str255);
  290.     PROCEDURE UseAppRes;
  291.         Inline    { move.w    CurApRefNum,-(sp) } $3f38, $0900,
  292.                 { _UseResFile } $a998;
  293.     FUNCTION  WasAborted: BOOLEAN;
  294.     
  295.     
  296. { Routines that are used internally withing ResEdit and may be useful in other
  297.     circumstances. }
  298.  
  299.     PROCEDURE CallEBirth (resHandle: Handle; parent: ParentHandle; id: INTEGER );
  300.     PROCEDURE CallEvent( VAR evt: EventRecord; refcon: LONGINT; id: INTEGER );
  301.     PROCEDURE CallMenu (menu, item: INTEGER; refcon: LONGINT; id: INTEGER);
  302.     PROCEDURE CallPBirth (theType: ResType; parent: ParentHandle; id: INTEGER );
  303.     FUNCTION  CopyRes (VAR h: Handle; makeID: BOOLEAN; resNew: INTEGER): Handle;
  304.     PROCEDURE DoKeyScan (var evt: EventRecord; offset: integer; lh: ListHandle);
  305.     PROCEDURE DoListEvt (e: EventRecord; l: ListHandle);
  306.     FUNCTION  DupPick (h: Handle; c: cell; pick: PickHandle): Handle;
  307.     FUNCTION  GetType (templatesOnly: BOOLEAN; VAR s: STR255): BOOLEAN;
  308.     PROCEDURE KillCache;
  309.     PROCEDURE MyCalcMask (srcPtr,dstPtr: Ptr; srcRow,dstRow,height,words: INTEGER);
  310.     FUNCTION  ResEditRes: INTEGER;
  311.         Inline    { move.w    CurApRefNum,(sp) } $3eB8, $0900;
  312.     PROCEDURE ScrapCopy ( VAR h: Handle );
  313.     PROCEDURE ScrapEmpty;
  314.     PROCEDURE ScrapPaste(pasteAll: BOOLEAN; typeToPaste: ResType; resFile: INTEGER);
  315.     
  316. { Obsolete routines that are left in for compatability. }
  317.  
  318.     FUNCTION  RevertResource (h: Handle): BOOLEAN;
  319.  
  320. END.
  321.  
  322.  
  323.  
  324.